<template>
	<el-button class="mb20" @click="add" type="primary">新增</el-button>

	<el-table class="mb20" :data="tableData" border style="width: 100%">
		
		<el-table-column prop="name" label="学校名称" />
		
		
		
	
		<el-table-column label="操作">
			<template #default="scope">
				<el-button size="mini"
					@click="edit({row:scope.row,index:scope.$index})">
					编辑</el-button>
				<el-button size="mini" type="danger" @click="removeModal({row:scope.row,index:scope.$index})">删除</el-button>
			</template>
		</el-table-column>
		
	</el-table>
	<!-- <el-pagination background layout="prev, pager, next" :total="1000">
	</el-pagination> -->
	<el-dialog v-model="modalState" title="学校">
		<el-form :model="form" ref="rule" :rules="rules">	
			<el-form-item label="学校名称" prop="name" :label-width="formLabelWidth">
				<el-input v-model="form.name" autocomplete="off"></el-input>
			</el-form-item>
		</el-form>
			<template #footer>
				<span class="dialog-footer">
					<el-button @click="modalState = false">取消</el-button>
					<el-button type="primary" @click="submit('rule')">确定</el-button>
				</span>
			</template>
	</el-dialog>
</template>

<script lang="ts">
	import {
		ElMessageBox,
		ElMessage
	} from 'element-plus'
	export default {
		data() {
			return {
				formLabelWidth: '120px',
				form: {
					name: '',
					tokenid:"nf2021113012336899abc"  
					
				},
				rules: {
					name: [{
						required: true,
						message: '请填写题目名称',
						trigger: 'blur',
					}],
					
				},
				pid: []
			}
		},
		mounted() {
			this.getData();
		},
		methods: {
			schange(val) {
				if (val == 1) {
					this.form.daan = "1"
				}
				if (val == 2) {
					this.form.daan = "A"
				}
				if (val == 3) {
					this.form.daan = ""
				}
			},
			getData() {
				this.$http.post("/index.php/index/Userinfo/schoollist",{tokenid:'nf2021113012336899abc'}).then(data => {

					this.tableData = data


				})
			},
			submit(ref) {
				console.log(this.$refs)
				this.doRules(this.$refs[ref]).then(() => {
					if (this.id) this.form.id = this.id;
                     this.form.tokenid="nf2021113012336899abc"  
					this.$http.post(this.id ? '/index.php/index/Userinfo/schooledit' :
						"/index.php/index/Userinfo/schooladd",
						this.form).then(data => {
						console.log(data)
						this.modalState = false;
						ElMessage({
							message: this.id ? '编辑成功' : '新增成功',
							type: 'success',
						})
						this.getData();
					})
				})

			},
			remove(data) {
				this.$http.post("/index.php/index/Userinfo/schooldel", {
					id: data.row.id,
					tokenid:"nf2021113012336899abc"  
				}).then(data => {
					ElMessage({
						message: '删除成功',
						type: 'success',
					})
					this.getData();
				})
			},
			handleAvatarSuccess(file) {

				this.form.image = file.data;
			},



		}
	}
</script>
